using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Player_VFX : Entity_VFX
{
    [Header("Fade Details")]
    [SerializeField] private GameObject imageEchoPrefab;
    [Range(.01f,0.1f)]
    [SerializeField] private float createEncoInterval = .05f;
    private Coroutine imageEchoCoroutine;


    
    public void DoImageEffectCo(float duration)
    {
        if (imageEchoCoroutine != null)
            StopCoroutine(ImageEchoEffectCo(duration));
        imageEchoCoroutine = StartCoroutine(ImageEchoEffectCo(duration));
    }
    private IEnumerator ImageEchoEffectCo(float duration)
    {
        float timer = 0;
        while (timer < duration)
        {
            CreateImageEcho();
            yield return new WaitForSeconds(createEncoInterval);
            timer += createEncoInterval;
        }
    }
    private void CreateImageEcho()
    {
        GameObject prefab = PoolManager.Instance.Release(imageEchoPrefab, (imageEchoPrefab) =>
        {
            imageEchoPrefab.transform.position = transform.position;
            imageEchoPrefab.transform.rotation = transform.rotation;
        });
        prefab.GetComponentInChildren<SpriteRenderer>().sprite = spriteRenderer.sprite;
    }
}
